<?php defined('SYSPATH') OR die('No direct access allowed.');

class Edit_Controller extends Master_Playlist_Controller 
{
	public function __call($method, $arguments)
     {
        $this->edit_playlist($method);
     }
	public function edit_playlist($playlist_id)
	{
		$playlists = new Playlists_Model;
		$_playlist = $playlists->find_playlist_detail($playlist_id);
		$playlist = $_playlist[0];


		$_playlist_song = $playlists->find_playlist_song($playlist_id);




			$hidDIV_count = 0;
			foreach ($_playlist_song as $playlist_song): 
				$divID = 'songDIV'. ($hidDIV_count+1);
				$hidID = 'hidID'. ($hidDIV_count+1);
				$songId = $playlist_song['album_id'].'-'.$playlist_song['track_no'];
				
				$song_result = $playlists->search_song($playlist_song['album_id'],$playlist_song['track_no']);
				$songText = $song_result[0]['song_title'];


	    		$hidDIV[$hidDIV_count] = '<div id="'.$divID.'">- '.$songText.' has been added! &nbsp;<a href="javascript:;" onclick="removeDIV(\''.$divID.'\')">Delete</a><input type="hidden" value="'. $songId .'" id="'. $hidID.'" name="'. $hidID.'" /></div>';
				$hidDIV_count ++;
			endforeach;


		$view = new View('playlist/create');
		$view->content = $playlist_id;

		$form = array (
					'txtTitle'    => $playlist['title'],
					'txtDesc'    => $playlist['description'],
					'txtPicture' => $playlist['playlist_logo'],
					'arrhidDIV' => $hidDIV,
					'numhidDIV' => $hidDIV_count+1,
					'hidMode' =>  $playlist_id,
				);
		$view->form = $form;

		$view->albums = $playlists->load_albums();
		$view->songs = $playlists->load_songs(1);

		$this->set_title('แก้ไข playlist');
		$this->template->content = $view;
		$this->template->render(TRUE);
	}

}
